// AftpClient.h: interface for the AftpClient class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_AFTPCLIENT_H__62AA93EF_DE46_4443_A069_29A03FCF4640__INCLUDED_)
#define AFX_AFTPCLIENT_H__62AA93EF_DE46_4443_A069_29A03FCF4640__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <vector>
#include <string>
#include <list>

#define AFTP_SUCCESS				0
#define AFTP_DATA_NOT_EXIST			410
#define AFTP_OPEN_FILE_ERROR		800
#define AFTP_READ_FILE_ERROR		810
#define AFTP_INVALIDATE_FILE_SIZE	820

#define LOG_TO_FILE

class VSocket;
class AftpResult;

typedef void* (*ParseFun)(const std::vector<std::string>& lines, int* data_length);
typedef void (_stdcall *ProgressFun)(int percent, void* param);

class AftpClient  
{
public:
	AftpClient();
	virtual ~AftpClient();
	void connect(const char* address, unsigned short port);
	void close();
	AftpResult* ping() const;
	AftpResult* auth(const char* username, const char* password) const;
	AftpResult* createToken() const;
	AftpResult* upload(const char* token, long length, const char* data) const;
	AftpResult* uploadFile(const char* token, const char* fileName, ProgressFun progressFun, void* param) const;
	AftpResult* info(const char* token) const;
	AftpResult* check(const char* token, const char* checkcode) const;
	AftpResult* commit(const char* token, const char* commitTag) const;
	AftpResult* reset(const char* token) const;
protected:
	AftpResult* executeWithBody(const char* ins, int dataSize, const char* buf, ParseFun parser, const std::vector<std::string>& args) const;
	AftpResult* executeWithFile(const char* ins, const char* filename, __int64 startPos, ParseFun parser, 
		std::vector<std::string>& args, ProgressFun progressFun, void* param) const;
	AftpResult* execute(const char* ins, ParseFun parser, const std::vector<std::string>& args) const;
	AftpResult* execute_list(const char* ins, ParseFun parser, const std::list<std::string>& args_list) const;
	void send_header(const char* ins, const std::vector<std::string>& args) const;
	AftpResult* recv_result(ParseFun parser) const;
	void read_result(std::string& line) const;
private:
	VSocket* m_pSocket;
};

void log_to_file(const char* str);

#endif // !defined(AFX_AFTPCLIENT_H__62AA93EF_DE46_4443_A069_29A03FCF4640__INCLUDED_)
